#include <iostream>
using namespace std;
struct type {
  int i;

  type() : i(3) {}

  void f(int v) const {
    // this->i = v;                 // compile error: this is a pointer to const
    const_cast<type *>(this)->i =
        v; // OK as long as the type object isn't const
  }
};

int main() {
  int i = 3; // i is not declared const   hhhfk
  const int &rci = i;
  const_cast<int &>(rci) = 4; // OK: modifies i
  std::cout << "i = " << i << '\n';

  type t; // if this was const type t, then t.f(4) would be undefined behavior
  t.f(4);
  std::cout << "type::i = " << t.i << '\n';

  const int j = 3; // j is declared const
  int *pj = const_cast<int *>(&j);
  *pj = 4; // undefined behavior
//   *(reinterpret_cast<int *>(&j)) = 5;
  cout << "j" << j << endl;
  void (type::*pmf)(int) const = &type::f; // pointer to member function
  // const_cast<void(type::*)(int)>(pmf);   // compile error: const_cast does
  // not work on function pointers
}